package org.budo.filestore.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.budo.filestore.api.DownloadRequest;

/**
 * @author lmw
 */
public class DefaultDownloadRequest extends AbstractRequest implements DownloadRequest, Serializable {
    private static final long serialVersionUID = -6177635669354938024L;

    private Map<String, Object> parameterMap = new HashMap<String, Object>();

    public DefaultDownloadRequest() {}

    public DefaultDownloadRequest(String contentUrl) {
        this.setContentUrl(contentUrl);
    }

    public Map<String, Object> getParameterMap() {
        return parameterMap;
    }

    public DefaultDownloadRequest setParameterMap(Map<String, Object> parameterMap) {
        this.parameterMap = parameterMap;
        return this;
    }

    public synchronized DefaultDownloadRequest setParameter(String key, Object value) {
        if (null == parameterMap) {
            parameterMap = new HashMap<String, Object>();
        }

        parameterMap.put(key, value);
        return this;
    }

    public Object getParameter(String key) {
        return null == parameterMap ? null : parameterMap.get(key);
    }

    @Override
    public String toString() {
        return super.toString() + ", contentUrl=" + this.getContentUrl() + ", parameterMap=" + this.getParameterMap();
    }
}
